﻿package com.pool.data 
{
	import com.pool.core.MinDesk;
	
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	import org.dm.net.GNID;
	import org.dm.objSys.NetObjC;
	import org.dm.utils.Map;
	//import SpLib.ObjSys.NetObjMgr;
	/**
	 * ...
	 * @author Scott
	 */
	public class RoomMgr extends NetObjC
	{
		private static var _instance:RoomMgr;
		
		public var roomLink:String;		//房间连接地址
		public var roomName:String;		//房间显示名称
		public var roomNo:String;		//房间号
		
		//private var _usersData:UserData;	//房间里所以人员数据
		private var _desksData:Map;			//房间里所有桌子
		private var _userData:UserDataMgr;			//房间里所有的人
		
		private var _timerHeart:Timer;
		
		public static function get Instance():RoomMgr
		{
			if(_instance==null)
			{
				_instance = new RoomMgr();
			}
			return _instance;
		}
		
		public function RoomMgr()
		{
			super();
			_desksData = new Map();
			UserDataMgr.Instance.addGroup("room",new UserDataMgr());
			_userData =UserDataMgr.Instance.getGroup("room");
		}
		
		//加入房间
		public function join():void 
		{
			this.JoinGroup(roomLink, roomNo, "CRoomUser", [UserDataMgr.meNetKey]);
			//this.addEventListener(NetObjC.REMOTECRAETE, createall);
			_timerHeart = new Timer(Common.DEF_RPC_OUTTIME);
			_timerHeart.addEventListener(TimerEvent.TIMER, roomHeart);
			_timerHeart.start();
		}
		
		//离开房间
		public function leave():void 
		{
			_timerHeart.stop();
			_timerHeart.removeEventListener(TimerEvent.TIMER, roomHeart);
		}
		
		//房间的心跳
		public function roomHeart(e:TimerEvent):void 
		{
			Common.RegCallBack("人员心跳", "Act", [UserDataMgr.me.netkey],null, true, 30000);
		}
		
		//房间加入桌子
		public function addRoomDesk(parms:Array=null):Boolean 
		{
			
			return _desksData.insert(parms, new MinDesk(0, 0));
		}
		
		//房间删除桌子(基本用不到)
		public function removeDesk(Guid:GNID):void 
		{
			_desksData.remove(Guid);
		}
		
		//玩家加入房间
		/*public function addRoomUser(Guid:GNID=null):void
		{
			_userData.Add("faf",new UserData("daf",[]));
		}*/
		
		//玩家离开房间
		public function removeUser(netkey:String):void 
		{
			_userData.Del(netkey);
		}
		
		//玩家加入某桌子
		public function joinDesk():void
		{
			
		}
		
		//玩家离开桌子
		public function leaveDesk():void 
		{
			
		}
		
		//玩家准备
		public function preInDesk():void 
		{
			
		}
		
		//玩家取消准备
		public function cancelInDesk():void 
		{
			
		}
	}

}